package com.example.administrator.managesystem.base;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.administrator.managesystem.manager.WrapContentLinearLayoutManager;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

/**
 * Description
 * Created by Administrator
 * Time 2018/1/4  23:32
 */

public class BaseHelper {
    private static void setLinearLayoutManager(Context context, XRecyclerView recyclerView, XRecyclerView.Adapter adapter, int direction){
        if(context==null||recyclerView==null||adapter==null){
            throw new IllegalArgumentException("setLinearLayoutManagerVertical has null params!");
        }
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
//        linearLayoutManager.setOrientation(direction);
        //允许刷新，加载更多
        recyclerView.setPullRefreshEnabled(true);
        recyclerView.setLoadingMoreEnabled(true);

        recyclerView.setLayoutManager(new LinearLayoutManager(context));
       // recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        ((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        // 可以设置加载更多的样式，很多种
        recyclerView.setRefreshProgressStyle(ProgressStyle.BallBeat);
        recyclerView.setLoadingMoreProgressStyle(ProgressStyle.Pacman);
        recyclerView.setAdapter(adapter);

      // 如果设置上这个，下拉刷新的时候会显示上次刷新的时间
        recyclerView.getDefaultRefreshHeaderView().setRefreshTimeVisible(true);  // make refresh time visible,false means hiding
    }
    public static void setLinearLayoutManagerVertical(Context context, XRecyclerView recyclerView, RecyclerView.Adapter adapter){
        setLinearLayoutManager(context,recyclerView,adapter, LinearLayoutManager.VERTICAL);
    }
    public static void setLinearLayoutManagerHorizontal(Context context, XRecyclerView recyclerView, RecyclerView.Adapter adapter){
        setLinearLayoutManager(context,recyclerView,adapter, LinearLayoutManager.HORIZONTAL);
    }
}
